import { createRouter, createWebHistory } from "vue-router";
import { useUserInfoStore } from '../store/userInfo';
import pinia from '../store';
import routes from "./routes";
const userInfoStore = useUserInfoStore(pinia);
const router = createRouter({
    history: createWebHistory(),
    routes //路由在routes文件里写
});

let blackList = ['/user','/shopCar']
// 路由前置守卫
router.beforeEach((to, from, next) => {
    if (!blackList.includes(to.fullPath)) {
        next()
    } else {
        const userInfoStore = useUserInfoStore()
        let token = userInfoStore.token
        if (token) {
            next()
        } else {
            next('/login' + `?redirect=${to.fullPath}`)
        }
    }
})
export default router;
